<?php
// +----------------------------------------------------------------------
// | HkCms 自定义页列表验证层
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2019 http://www.hkcms.cn, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 广州恒企教育科技有限公司 <admin@hkcms.cn>
// +----------------------------------------------------------------------

namespace app\template\validate;

use think\Validate;

class Customlist extends Validate
{
    protected $rule = [
        'name' => 'require|min:1|unique:Customlist',
        'title' => 'require|min:1',
        'totalsql' => 'require',
        'listsql' => 'require',
        'lencord' => 'require',
    ];

    protected $message = [
        'name.require'  =>  '自定义列表名称不能为空',
        'name.min'  =>  '自定义列表名称不能为空',
        'name.unique'  =>  '该自定义列表已经存在',
        'title.require'  =>  '自定义列表页面标题不能为空',
        'title.min'  =>  '自定义列表页面标题不能为空',
        'totalsql.require'  =>  '数据统计SQL不能为空！',
        'listsql.require'  =>  '数据查询SQL不能为空！',
        'lencord.require'  =>  '每页显示数量不能为空！',
        'urlruleid.require'  =>  'URL规则不能为空！',
        'urlrule.require'  =>  'URL规则不能为空！',
        'template.require'  =>  '模板内容不能为空！',
        'listpath.require'  =>  '列表模板不能为空！',
    ];

    /**
     * 基本验证场景定义
     * @return mixed
     */
    public function sceneBase()
    {
        $rule = $this->rule;

        //检查是否使用已有URL规则
        if (input('isurltype') == 1) {
            $rule['urlruleid'] = 'require';
        } else {
            $rule['urlrule'] = 'require';
        }

        //模板
        if (empty($post['listpath'])) {
            $rule['template'] = 'require';
        } else {
            $rule['listpath'] = 'require';
        }
        return [$this->rule,$this->message];
    }
}